package cn.xiaoqintools.studypark.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.widget.Toast;

import butterknife.ButterKnife;
import cn.xiaoqintools.studypark.R;


/**
 * Created by joyisn on 2015/12/2.
 */
public class BaseActivity extends AppCompatActivity {

    protected LayoutInflater mInflater;



    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }
    @Nullable
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        onBeforeSetContentLayout();
        if (getLayoutId() != 0) {
            setContentView(getLayoutId());
        }
        mInflater = getLayoutInflater();

        // 通过注解绑定控件
        ButterKnife.bind(this);

        init(savedInstanceState);
        initViews();
        initData();
    }

    protected void onBeforeSetContentLayout() {
    }

    @Override
    public void finish() {
        super.finish();
    }

    /**
     * 复写退出方法，避免内存泄露
     *
     * @author zzd
     *
     * created at 2015/12/29 21:16
     */
    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    /**
     * 由右往左滑动进入
     */


    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    protected void init(Bundle savedInstanceState) {
    }

    protected void initViews() {

    }

    protected void initData() {
    }

    private void setUpToolbar() {

    }


    protected void showToast(int resId) {
        showToast(getString(resId));
    }

    protected void showToast(String text) {
        Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
    }


}
